package com.itheima.springbootwebbtalis.service.Impl;

import com.itheima.springbootwebbtalis.mapper.EmpMapper;
import com.itheima.springbootwebbtalis.mapper.StudentMapper;
import com.itheima.springbootwebbtalis.service.ReportService;
import com.itheima.springbootwebbtalis.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public Map jobCount() {
        // 1.调用持久层，查询职位统计数据
        List<Map> jobList =empMapper.jobCount();
        // 2.处理查询结果
        Map map = new HashMap();
        map.put("jobList",  jobList.stream().map(item->item.get("name")).collect(Collectors.toList()));
        map.put("dataList",  jobList.stream().map(item->item.get("value")).collect(Collectors.toList()));
        return map;
    }

    @Override
    public List<Map> genderCount() {
        return empMapper.genderCount();
    }
// 班级统计
    @Override
    public Map clazzCount() {
        List<Map> clazzList =studentMapper.clazzCount();
        Map map = new HashMap();
        map.put("clazzList",  clazzList.stream().map(item->item.get("name")).collect(Collectors.toList()));
        map.put("dataList",  clazzList.stream().map(item->item.get("value")).collect(Collectors.toList()));
        return map;
    }

    @Override
    public List<Map> degreeCount() {
        return studentMapper.degreeCount();
    }
}
